home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 005 / parallel / parallel.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  4KB  |  140 lines

  1. /*
  2.  *
  3.  *    DISCLAIMER:
  4.  *
  5.  *    This program is provided as a service to the programmer
  6.  *    community to demonstrate one or more features of the Amiga
  7.  *    personal computer.  These code samples may be freely used
  8.  *    for commercial or noncommercial purposes.
  9.  * 
  10.  *     Commodore Electronics, Ltd ("Commodore") makes no
  11.  *    warranties, either expressed or implied, with respect
  12.  *    to the program described herein, its quality, performance,
  13.  *    merchantability, or fitness for any particular purpose.
  14.  *    This program is provided "as is" and the entire risk
  15.  *    as to its quality and performance is with the user.
  16.  *    Should the program prove defective following its
  17.  *    purchase, the user (and not the creator of the program,
  18.  *    Commodore, their distributors or their retailers)
  19.  *    assumes the entire cost of all necessary damages.  In 
  20.  *    no event will Commodore be liable for direct, indirect,
  21.  *    incidental or consequential damages resulting from any
  22.  *    defect in the program even if it has been advised of the 
  23.  *    possibility of such damages.  Some laws do not allow
  24.  *    the exclusion or limitation of implied warranties or
  25.  *    liabilities for incidental or consequential damages,
  26.  *    so the above limitation or exclusion may not apply.
  27.  *
  28.  */
  29.  
  30. /* parallel.c .... parallel port test program. */
  31.  
  32. /* author:  Tom Pohorsky, 12/1/85 */
  33.  
  34.  
  35. #include        "exec/types.h"
  36. #include        "exec/nodes.h"
  37. #include        "exec/lists.h"
  38. #include        "exec/ports.h"
  39. #include        "exec/libraries.h"
  40. #include        "exec/devices.h"
  41. #include        "exec/io.h"
  42. #include        "devices/parallel.h"
  43.  
  44. struct IOExtPar IORpar;
  45. struct MsgPort *port;
  46. char   buffer[64000];
  47. extern struct MsgPort *CreatePort();
  48.  
  49. main()
  50. {
  51.     int     error;
  52.     int     actual;
  53.     unsigned char pflags;
  54.     unsigned long pt0;
  55.     unsigned long pt1;
  56.  
  57. open:
  58.  /* OPEN the parallel.device */
  59.     if ((error = OpenDevice (PARALLELNAME, 0, &IORpar, 0)) != 0) {
  60.         printf ("bad news %ld on Open \n", error);
  61.         exit (error);
  62.     }
  63.  
  64.  /* SET UP the message port in the I/O request */
  65.     port = CreatePort (PARALLELNAME,0);
  66.     IORpar.IOPar.io_Message.mn_ReplyPort = port;
  67.  
  68. /*    SET PARAMS for the parallel.device */
  69.     pflags = PARF_EOFMODE;
  70.     pt0  = 0x51040303;
  71.     pt1  = 0x03030303;
  72.  
  73.   if ((error = setparams (pflags,pt0,pt1)) != 0) {
  74.         printf ("bad news %ld on setup \n", error);  
  75.         DeletePort();
  76.         exit (error);
  77.     } 
  78.  
  79.     actual = readPar (buffer,60000);
  80.  
  81.  /* CLOSE the parallel.device */
  82.     CloseDevice (&IORpar);
  83.     DeletePort (port);
  84.     exit (0);
  85. }
  86.  
  87.  /* PARALLEL I/O functions */
  88.  
  89. setparams(pf,ta0,ta1)
  90.  
  91.     unsigned char pf;
  92.     unsigned long ta0;
  93.     unsigned long ta1;
  94.  
  95. {
  96.     int error;
  97.  
  98.     IORpar.io_ParFlags      = pf;
  99.     IORpar.IOPar.io_Command = PDCMD_SETPARAMS;
  100.     IORpar.io_PTermArray.PTermArray0 = ta0;
  101.     IORpar.io_PTermArray.PTermArray1 = ta1;
  102.  
  103.     if ((error = DoIO (&IORpar)) != 0) {
  104.         printf ("parallel.device setparams error %ld \n", error);
  105.     }
  106.     return (error);
  107. }
  108.  
  109. readPar(data,length)
  110.     char *data;
  111.     ULONG length;
  112. {
  113.     int error;
  114.  
  115.     IORpar.IOPar.io_Data = data;
  116.     IORpar.IOPar.io_Length = length;
  117.     IORpar.IOPar.io_Command = CMD_READ;
  118.  
  119.     if ((error = DoIO (&IORpar)) != 0) {
  120.         printf ("parallel.device read error %ld \n", error);
  121.     }
  122.     return (IORpar.IOPar.io_Actual);
  123. }
  124.  
  125. writePar(data,length)
  126.     char *data;
  127.     int length;
  128. {
  129.     int     error;
  130.  
  131.     IORpar.IOPar.io_Data = data;
  132.     IORpar.IOPar.io_Length = length;
  133.     IORpar.IOPar.io_Command = CMD_WRITE;
  134.  
  135.     if ((error = DoIO (&IORpar)) != 0) {
  136.         printf ("parallel.device write error %ld \n", error);
  137.     }
  138.     return (error);
  139. }
  140.